#include "stdafx.h"
#include "DlgLogin.h"

DlgLogin::DlgLogin()
{
}


DlgLogin::~DlgLogin()
{
	DestroyWindow();
}

void DlgLogin::DestroyWindow()
{
	if (m_wnd_dlg)
	{
		m_wnd_dlg->destroy();
		m_wnd_dlg = nullptr;
	}
}

void DlgLogin::InitWindow(CEGUI::Window *parent)
{
	//m_entryYpos_group = CEGUI::UDim(0.54f, 0.f);
	//m_entryWidth_group = CEGUI::UDim(0.0f, 134.f);
	//m_entryHeight_group = CEGUI::UDim(0.0f, 30.f);
	//m_entryWidth_line = CEGUI::UDim(0.0f, 180.f);
	//m_entryHeight_line = CEGUI::UDim(0.0f, 36.f);
	//m_wnd_groupList = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow");
	////m_wnd_groupList = new CEGUI::Window("DefaultWindow","");
	m_wnd_dlg = CEGUI::WindowManager::getSingleton().loadLayoutFromFile("dlg_login.layout");
	//m_wnd_dlg->setArea(CEGUI::UDim(0.f, 0.f), CEGUI::UDim(0.54f, 0.f), m_entryWidth_group, m_entryHeight_group);
	//m_wnd_dlg->setHorizontalAlignment(CEGUI::HorizontalAlignment::HA_CENTRE);

	//auto wnd = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Button");
	m_wnd_dlg->getChild("login")->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&DlgLogin::SignIn_OnClicked, this));
	//wnd->setID(0);

	parent->addChild(m_wnd_dlg);
	m_wnd_dlg->hide();
}

void DlgLogin::Show()
{
	m_wnd_dlg->show();
}

void DlgLogin::Hide()
{
	m_wnd_dlg->hide();
}

void DlgLogin::SignIn_OnClicked(/*const CEGUI::EventArgs& args*/)
{
	auto wnd = m_wnd_dlg->getChild("username");
	auto username = wnd->getText().c_str();
	wnd = m_wnd_dlg->getChild("password");
	auto password = wnd->getText().c_str();

	if (m_cb_SignIn)
	{
		m_cb_SignIn((char*)username, (char*)password);
	}
	int i = 0;
}

void DlgLogin::Quit_OnClicked(const CEGUI::EventArgs& args)
{

}

